package fashionshop.gui.common.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public abstract class ModelData implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	protected Map<String, Object> props;
	protected Collection<String> names;
	
	public ModelData(){
	}
	
	@SuppressWarnings("unchecked")
	public <X> X get(String property){
		return (X)getProperties().get(property);
	}
	
	@SuppressWarnings("unchecked")
	public <X> X set(String property, X value){
		if(props != null){
			return (X)props.put(property, value);
		}
		return null;
	}
	
	public Map<String, Object> getProperties(){
		if(props == null){
			props = new HashMap<String, Object>();
			populateProps(props);
		}
		return props;
	}
	
	public Collection<String> getPropertyNames(){
		if(names == null){
			names = new ArrayList<String>();
			populateNames(names);
		}
		return names;
	}
	
	protected abstract void populateNames(Collection<String> names);
	protected abstract void populateProps(Map<String, Object> props);

}
